﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
public enum EnemyTransition
{
    NullTransition = 0, //空的
    CanAttack,           //看到士兵
    LostSoldier             //丢失士兵
            
}

public enum EnemyStateID
{
    NullState,//空状态
    Chase, //追击
    Attack //攻击
}
///<summary>
///IEnemyState
///</summary>
public abstract class IEnemyState
{
    /// <summary>
    /// 存储所以转换条件  转换条件 转换状态
    /// </summary>
    protected Dictionary<EnemyTransition, EnemyStateID> mMap = new Dictionary<EnemyTransition, EnemyStateID>();
    /// <summary>
    /// 自己的状态
    /// </summary>
    protected EnemyStateID mStateID;

    protected ICharacter mCharacter; // 取到控制的角色
    protected EnemyFSMSystem mFsm;

    public IEnemyState(EnemyFSMSystem fsm, ICharacter character)
    {
        mFsm = fsm;
        mCharacter = character;
    }

    public EnemyStateID stateID
    {
        get { return mStateID; }
    }

    /// <summary>
    /// 添加状态
    /// </summary>
    /// <param name="trans"></param>
    /// <param name="id"></param>
    public void AddTransition(EnemyTransition trans, EnemyStateID id)
    {
        if (trans == EnemyTransition.NullTransition)
        {
            Debug.LogError("IEnemyStateError: EnemyTransition 不能为空");
            return;
        }
        if (id == EnemyStateID.NullState)
        {
            Debug.LogError("IEnemyStateError: EnemyStateID 不能为空");
            return;
        }
        if (mMap.ContainsKey(trans))
        {
            Debug.LogError("IEnemyStateError:EnemyState已经存在了");
            return;
        }
        mMap.Add(trans, id);
    }

    /// <summary>
    /// 删除某个状态
    /// </summary>
    /// <param name="trans"></param>
    public void DeleteTransition(EnemyTransition trans)
    {
        if (mMap.ContainsKey(trans) == false)
        {
            Debug.LogError("删除转换条件:[" + trans + "]不存在");
            return;
        }
        mMap.Remove(trans);
    }

    /// <summary>
    /// 获得某个转换条件的状态 类型
    /// </summary>
    /// <param name="trans"></param>
    /// <returns></returns>
    public EnemyStateID GetOutPutState(EnemyTransition trans)
    {
        if (mMap.ContainsKey(trans) == false)
        {

            return EnemyStateID.NullState;
        }
        else
        {
            return mMap[trans];
        }
    }

    #region //有的状态可能要初始化可以选择性重写

    public virtual void DoBeforeEntering() { }

    public virtual void DoBeforeLeaving() { }
    #endregion

    /// <summary>
    /// 判断是否需要转换到别的状态
    /// </summary>
    /// <param name="targets">目标集合</param>
    public abstract void Reason(List<ICharacter> targets);
    /// <summary>
    /// 处理当前状态的游戏逻辑
    /// </summary>
    public abstract void Act(List<ICharacter> targets);
}

